package cn.dakaqi.utils.rongYun;

import cn.dakaqi.utils.BaseDAO;
import cn.dakaqi.utils.DKQConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 活动小助手
 * Created by chunyang on 2016/6/5.
 */
public class PushActivityMesssage
{

    public static final String TYPE_ACTIVITY_SIGN_PAGE = "ACTIVITY_SIGN_PAGE";  //活动签到/签出
    public static final String TYPE_ACTIVITY_DIARY_PAGE = "ACTIVITY_DIARY_PAGE"; //活动日记
    public static final String TYPE_ACTIVITY_MANAGER_PAGE = "ACTIVITY_MANAGER_PAGE"; //活动管理
    public static final String TYPE_ACTIVITY_RECRUIT_PAGE = "ACTIVITY_RECRUIT_PAGE"; //审核活动招募人员
    public static final String TYPE_ACTIVITY_COMMENT_VOLUNTEER_PAGE = "ACTIVITY_COMMENT_VOLUNTEER_PAGE"; //评介志愿者
    public static final String TYPE_ACTIVITY_COMMENT_VOLUNTEER_LIST_PAGE = "ACTIVITY_COMMENT_VOLUNTEER_LIST_PAGE"; //评介志愿者列表
    //活动小助手
    public static final String ACTIVITY_HELPER = "1bb148f5-6b78-4b7d-a783-0ed293d83697";

    static PushActivityMesssage pushActivityMesssage = null;

    private PushActivityMesssage()
    {
    }

    /**
     * 类级的内部类，也就是静态的成员式内部类，该内部类的实例与外部类的实例
     * 没有绑定关系，而且只有被调用到时才会装载，从而实现了延迟加载。
     */
    private static class SingletonHolder
    {
        /**
         * 静态初始化器，由JVM来保证线程安全
         */
        private static PushActivityMesssage instance = new PushActivityMesssage();
    }

    public static PushActivityMesssage getInstance()
    {
        return SingletonHolder.instance;
    }

    /**
     * 报名参加一个活动招募
     */
    public void applyActivityRecruit(String name,String memberCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        PushMessageUtil.pushMessage("您提交了"+name+"的申请，正在审核中，请耐心等待。", null, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 提示管理员审核活动招募成员
     * @param volunterName
     * @param volunteerMemberCode
     * @param actName
     * @param memberCode
     */
    public void verfierActivityRecruit(String volunterName,String volunteerMemberCode,String actName,String memberCode,String activityCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityCode",activityCode);
        params.put("otherMemberCode",volunteerMemberCode);
        params.put("type", TYPE_ACTIVITY_RECRUIT_PAGE);
        PushMessageUtil.pushMessage(volunterName + "报名参加"+actName+"招募，点击审核。", params, ACTIVITY_HELPER, volunteers);
    }
    /**
     * 提示有待评论的志愿者
     * @param name
     * @param memberCode
     */
    public void commentVolunteer(String name,String memberCode,long activitySignId)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();
        params.put("activitySignId",activitySignId+"");
        params.put("type",TYPE_ACTIVITY_COMMENT_VOLUNTEER_PAGE);
        PushMessageUtil.pushMessage(name + "已经完成了本次活动,快去给他评价吧。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 提示有待评论的志愿者列表
     * @param name
     * @param memberCode
     */
    public void commentVolunteerList(String name,String memberCode,String activityCode,String activityName)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityCode",activityCode+"");
        params.put("activityName",activityName);
        params.put("type",TYPE_ACTIVITY_COMMENT_VOLUNTEER_LIST_PAGE);
        PushMessageUtil.pushMessage(name + "已经完成了本次活动,快去给他评价吧。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 活动封存提示
     * @param name
     * @param volunteers
     */
    public void locked(String name,List<String> volunteers)
    {
        //推送消息至志愿者用户
        PushMessageUtil.pushMessage(name + "活动数据已经提交到国家数据库，并封存，不可修改。", null, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 同意申请人参加活动招募
     * @param name
     * @param memberCode
     */
    public void agreeActivityRecruit(String name,String memberCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();

        PushMessageUtil.pushMessage(name + "活动招募同意了您的申请，您已经是该活动成员，请准时参加哦。", params, ACTIVITY_HELPER, volunteers);
    }


    /**
     * 提示活动可以进行签到
     * @param activityId
     * @param actName
     */
    public void startSignIn(BaseDAO baseDAO,long activityId,String actName,String activityCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        //查询活动的所有报名记录
        String sql = "SELECT MEMBER_CODE FROM U_VOLUNTEER AS A INNER JOIN (SELECT VOLUNTEER_ID FROM U_ACTIVITY_APPLY WHERE ACTIVITY_ID = " + activityId + " AND STATUS = "+DKQConstant.APPLY_STATUS_OK+" AND DEL_STATUS = "  + DKQConstant.DEL_NO + ") AS B ON B.VOLUNTEER_ID = A.ID";
        List<Map<String,String>> list = baseDAO.queryNativeSql(sql);
        if(null != list && list.size()>0)
        {
            for(Map<String,String> map:list)
                volunteers.add(map.get("MEMBER_CODE"));
        }
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityCode",activityCode);
        params.put("type",TYPE_ACTIVITY_SIGN_PAGE);
        PushMessageUtil.pushMessage(actName+"活动可以进行签到了，点击签到。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 提示活动可以进行签出
     * @param activityId
     * @param actName
     */
    public void startSignOut(BaseDAO baseDAO,long activityId,String actName,String activityCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        //查询活动的所有报名记录
        String sql = "SELECT MEMBER_CODE FROM U_VOLUNTEER AS A INNER JOIN (SELECT VOLUNTEER_ID FROM U_ACTIVITY_APPLY WHERE ACTIVITY_ID = " + activityId + " AND STATUS = "+DKQConstant.APPLY_STATUS_OK+" AND DEL_STATUS = "  + DKQConstant.DEL_NO + ") AS B ON B.VOLUNTEER_ID = A.ID";
        List<Map<String,String>> list = baseDAO.queryNativeSql(sql);
        if(null != list && list.size()>0)
        {
            for(Map<String,String> map:list)
                volunteers.add(map.get("MEMBER_CODE"));
        }
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityCode",activityCode);
        params.put("type",TYPE_ACTIVITY_SIGN_PAGE);
        PushMessageUtil.pushMessage(actName+"活动可以进行签出了，点击签出。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 提示发布活动总结
     * @param name
     * @param memberCode
     */
    public void activityDiary(String name,String memberCode,String activityCode,String groupCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityName",name);
        params.put("activityCode",activityCode);
        params.put("groupCode",groupCode);
        params.put("type",TYPE_ACTIVITY_DIARY_PAGE);

        PushMessageUtil.pushMessage("您已经完成了" + name + "活动，快去写个活动总结吧。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 设置活动现场负责人
     * @param name
     * @param memberCode
     */
    public void setActivityMonitor(String name,String memberCode,String activityCode)
    {
        //推送消息至志愿者用户
        List<String> volunteers = new ArrayList<String>();
        volunteers.add(memberCode);
        Map<String, String> params = new HashMap<String, String>();
        params.put("activityCode",activityCode);
        params.put("type",TYPE_ACTIVITY_MANAGER_PAGE);
        PushMessageUtil.pushMessage("您为"+name+"活动的现场负责人，点击查看详情。", params, ACTIVITY_HELPER, volunteers);
    }

    /**
     * 志愿者退出活动
     * @param name
     * @param activityName
     * @param cause
     * @param volunteers
     */
    public void exitActivityApply(String name,String activityName,String cause,List<String> volunteers)
    {
        PushMessageUtil.pushMessage(name + "已退出"+activityName+",原因是 "+ cause, null, ACTIVITY_HELPER, volunteers);
    }
}
